/**
 * \file XMLAttribute.h
 * \brief XMLAttribute declaration class
 * \author Edouard ROGE
 * \date 16 October 2012
 */

#ifndef _XML_NODE_
#define _XML_NODE_

#include "Core/File/File.h"
#include "Core/File/XMLAttribute.h"
#include "Core/Memory/HeapObject.h"

namespace Core
{
	namespace File
	{
	/**
	 * \class XMLNode
	 * \brief Xml node that contains an xml element and may contain children
	 */
	class XMLNode : public Memory::HeapObject
	{
	public:

		/**
		 * \fn XMLNode();
		 * \brief Default constructor
		 */
		XMLNode();

		/**
		 * \fn virtual ~XMLNode();
		 * \brief Destructor
		 */
		virtual ~XMLNode();

		/**
		 * \fn void SetName(const String & _strName);
		 * \param _strName new name for the node
		 * \brief Set new node name
		 */
		void SetName(const std::string & _strName);

		/**
		 * \fn const String & GetName() const;
		 * \return the node name
		 * \brief Get new node name
		 */
		const std::string & GetName() const;

		/**
		 * \fn const Array<XMLNode *> & GetChildren() const;
		 * \return node children
		 * \brief Getter to the node children
		 */
		const std::vector<XMLNode *> & GetChildren() const;

		/**
		 * \fn XMLNode * GetChild(uint32 _iIndex) const;
		 * \param _iIndex index in the node children array
		 * \return the child corresponding to the index in the xml node array
		 * \brief return xml node from index in array
		 */
		XMLNode * GetChild(uint32 _iIndex) const;

		/**
		 * \fn void SetChildren(const Array<XMLNode *> & _nodeChildren);
		 * \param _nodeChildren node children
		 * \brief Set new children
		 */
		void SetChildren(const std::vector<XMLNode *> & _nodeChildren);

		/**
		 * \fn void AddChild(XMLNode * _nodeChild);
		 * \param _nodeChild node child to add
		 * \brief Add new xml node
		 */
		void AddChild(XMLNode * _nodeChild);

		/**
		 * \fn static XMLNode * Load(File & _file);
		 * \param _file file to read in
		 * \return the created node
		 * \brief Create a xml node with all its structure from a file
		 */
		static XMLNode * Load(File & _file);

		/**
		 * \fn virtual error Save(File & _file) const = 0;
		 * \param _file file to write in
		 * \return if success, returns errOK
		 * \brief Save in xml file
		 */
		virtual error Save(File & _file, uint32 _iDepth) const = 0;

	protected:

		/**
		 * \fn Array<XMLAttribute> GetAttribute(const String & _strLine) const;
		 * \param _strLine line to read to get attributes from
		 * \param _attributes attributes to fill according to the line
		 * \param _strName name of the node to fill
		 * \return errOK if everything went good
		 * \brief Retrieve the attribute array from the line given in parameter
		 */
		static error GetNameAndAttributes(const std::string & _strLine, std::vector<XMLAttribute*> & _attributes, std::string & _strName);


		/** name of the xml node */
		std::string m_strName;

		/** node's children */
		std::vector<XMLNode *> m_Children;

	};
}
}
#endif // _XML_NODE_
